Write back non-ASCII pantry key when updating#314
Write back non-ASCII pantry key when updating#314kthenrique wants to merge 2 commits intocooklang:mainfrom
Conversation
TOML doesn't support non-ASCII characters in keys. Such keys need to be inside quotes. When a pantry item is removed, the pantry conf is rewritten and need to consider TOML's constraint.
|
I'm trying to solve the same issue in #313 |
Code ReviewSummary: This PR correctly fixes the bug where non-ASCII pantry keys (e.g. Swedish å, ä, ö) were written back as unquoted bare TOML keys, producing invalid TOML on round-trip. What's correct
Issues / observations1. Incomplete escaping for edge cases The current escaping wraps in double quotes and only escapes internal format!("\"{}\"", key.replace('"', "\\\""))This is fine for typical ingredient names, but it doesn't escape backslash ( format!("\"{}\"", key.replace('\\', "\\\\").replace('"', "\\\""))2. Pre-existing code duplication
3. No tests There are no tests covering non-ASCII round-tripping. Given the fix is a one-liner it's low risk, but a test like 4. Related PR #313 PR #313 addresses the same root cause with a more comprehensive approach: it bumps VerdictThe fix is correct for the stated bug. The main concern is the backslash escaping gap. I'd recommend adding the backslash fix and a test before merging, or coordinating with #313 since they solve the same issue. |
Code ReviewWhat this PR doesAdds IssuesIncomplete TOML key escaping: TOML bare keys are restricted to Duplicated fix: The same change is applied to two separate copies of Superseded by PR #313: PR #313 removes the hand-rolled serialization entirely and delegates to RecommendationClose this PR in favour of #313, which provides a complete and correct solution to the same issue. If a quick patch is needed in the meantime, the fix here is directionally correct for the non-ASCII case specifically — just be aware of the remaining gaps. |
Code ReviewThis PR adds Potential IssuesConflict with PR #313 PR #313 (open, filed yesterday) solves this same bug more comprehensively by upgrading the No regression tests There is no automated test verifying that non-ASCII ingredient names survive a serialize/re-parse round-trip. PR #313 adds four tests covering this scenario, including Swedish characters ( Incomplete bare-key quoting TOML bare keys may only contain Code duplication remains
Comparison with PR #313
This PR is a correct minimal fix. PR #313 is the more maintainable long-term solution and is worth considering as the preferred approach. |
|
Duplicate of #313 |
TOML doesn't support non-ASCII characters in keys. Such keys need to be inside quotes. When a pantry item is removed, the pantry conf is rewritten and need to consider TOML's constraint.